<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<script type="text/javascript">
    if (typeof window.event != 'undefined') {
        document.onkeydown = function() {
            var type = event.srcElement.type;
            var code = event.keyCode;
            return ((code != 8 && code != 13) || (type == 'text' && code != 13)
                    || (type == 'textarea') || (type == 'submit' && code == 13))
        }
    } else { // FireFox/Others
        document.onkeypress = function(e) {

            var type = e.target.localName.toLowerCase();
            var code = e.keyCode;
            if ((code != 8 && code != 13) || (type == 'input' && code != 13)
                    || (type == 'textarea') || (type == 'submit' && code == 13)) {
                return true;
            } else {
                return false;
            }
        }
    }


    $.ajaxSetup({
        error:function(xhr, event, data) {
            if (eval("(" + xhr.responseText + ")").login) {
                if (top.frames.length > 0) {
                    top.location.href = "/login.xhtml";
                } else {
                    window.location.href = "/login.xhtml";
                }
            }
        },
        global:true
    })
var backUrl;
var thisUrl=document.location.href;
var isMainPage = false;
$(function(){
	$("#main").each(function(){
		isMainPage = true;
		return false;
	});
	
	/*$("a[name='content_href']").click(function(){
		var clkHref = $(this).attr("href");
		//?:* &:@
		var ret = "ret=/managehome.xhtml*url="
		if(-1 != clkHref.indexOf("?")){
			backUrl = clkHref + "&" + ret + clkHref.replace(new RegExp("\\?","g"),"*").replace(new RegExp("\\&","g"),"@");
		}else{
			backUrl = clkHref + "?" + ret + clkHref.replace(new RegExp("\\?","g"),"*").replace(new RegExp("\\&","g"),"@");
		}
		$(this).attr("href",backUrl);
	});*/
	$("#liPrev").click(function(){
		return goPrev();
	});
	/*$("a").click(function(){
		var mTgt = $(this).attr("target").toLowerCase();
		//alert(mTgt);
		if("main" == mTgt){
			//setRetUrl($(this),true);
		}else if("self" == mTgt || "_self" == mTgt){
			return setRetUrl($(this),false);
		}else{
			return setRetUrl($(this),true);
		}
	});*/
});
function setRetUrl(clk,useThis){
	var clkHref = $(clk).attr("href");
	var retUrl = "";
	var thisHost = document.location.host;
	if(useThis){
		retUrl = thisUrl;
	}else{
		retUrl = clkHref;
	}
	//alert(thisUrl);

	//alert($(clk).attr("href"));
	var ret = "ret=/managehome.xhtml*url=";
	//alert(-1 == clkHref.toLowerCase().indexOf(ret) );
	//alert(-1 == clkHref.toLowerCase().indexOf("javascript"));
	if(-1 == clkHref.toLowerCase().indexOf(ret) 
			&& -1 == clkHref.toLowerCase().indexOf("javascript")){
		//alert(1);
		if(-1 != clkHref.indexOf("?")){
			backUrl = clkHref + "&" + ret + retUrl.replace(new RegExp("\\?","g"),"*").replace(new RegExp("\\&","g"),"@");
		}else{
			backUrl = clkHref + "?" + ret + retUrl.replace(new RegExp("\\?","g"),"*").replace(new RegExp("\\&","g"),"@");
		}
		if(-1 != backUrl.toLowerCase().indexOf("http://" + thisHost)){
			backUrl = backUrl.replace("http://" + thisHost,"");
		}
		$(clk).attr("href",backUrl);
	}
	//alert($(clk).attr("href"));
}

function goPrev(){
	var hst = document.referrer;
	if(!isMainPage){
		history.go(-1);
	}else{
		history.go(-1);
	}
	return true;
	/*
	//alert(isMainPage);
	var hst = document.referrer;
	if(!isMainPage){
		if(-1 != hst.indexOf("index.xhtml")){
			document.location.href = "/index.xhtml";
		}else{
			var goUrl = thisUrl.substr(thisUrl.indexOf("ret=") + 4);
			//alert(goUrl);
			var newUrl = goUrl.replace(new RegExp("\\*","g"),"?").replace(new RegExp("\\@","g"),"&")
			//alert(newUrl);
			document.location.href = newUrl;
		}
	}else{
		//alert(hst);
		if(-1 == hst.indexOf("index.xhtml")
				&&-1 == hst.indexOf("login.xhtml")
				&&-1 == hst.indexOf("logout.xhtml")){
			main.history.go(-1);
		}else{
			return false;
		}
	}
	return true;*/
}
function eRefreshPage(){
	window.setTimeout(function(){
		window.location.href = location.href.replace(/#/g,'');;
	}, 100); 
}
</script>